require(['./config'], () => {
    require(['footer', 'jquery', 'cookie'], () => {
        class Login {
            constructor() {
                this.setcookie();
            }
            setcookie() {
                $('.my-login-btn').on('click', () => {
                    let info = $.cookie('info')
                    var usermail = $('.mail-inp').val()
                    var password = $('.pwd-inp').val()
                    if (usermail && password) {
                        if (info) {
                            info = JSON.parse(info)
                            var user = info.filter(user => {
                                if ($('.mail-inp').val() === user.mail && $('.pwd-inp').val() === user.password)
                                    return user
                            })
                            if (user.length !== 0) {
                                if ($('.dayseven').prop('checked')) {
                                    $.cookie('username', user[0].username, {
                                        expires: 7,
                                        path: '/'
                                    })
                                } else {
                                    $.cookie('username', user[0].username, {
                                        path: '/'
                                    })

                                }
                                alert('登录成功')
                                location.href = "/index.html"
                            } else {
                                $('.mail-inp').val('')
                                $('.pwd-inp').val('')
                                alert("信息错误，请重新输入！")
                            }
                        } else {
                            alert('用户不存在，请注册')
                        }

                    } else {
                        alert('信息不能为空')
                    }


                })
            }
        }

        new Login()
    });
})